'''
Created on 2012-7-11

@author: Legendxcheng
'''

from django.db import models
from django.contrib.auth.models import User
from django.contrib import admin
from django.core.mail import send_mail

class BlogCategory(models.Model):
    name = models.CharField(max_length=60)
    def __unicode__(self):
        return self.name

class ProjectPost(models.Model):
    title = models.CharField(max_length=60)
    brief = models.CharField(max_length=500)#plain text
    briefPic = models.CharField(max_length=250) #brief picture size 100 * 100
    body = models.TextField()
    created = models.DateTimeField(auto_now_add=True) #    not display
    
    
    def __unicode__(self):
        return self.title

class GameDesignPost(models.Model):
    title = models.CharField(max_length=60)
    brief = models.CharField(max_length=500)#plain text
    briefPic = models.CharField(max_length=250) #brief picture size 100 * 100
    body = models.TextField()
    created = models.DateTimeField(auto_now_add=True) #    not display
    
    def __unicode__(self):
        return self.title

class ArtPost(models.Model):
    title = models.CharField(max_length=60)
    brief = models.CharField(max_length=500)#plain text
    smallPic = models.CharField(max_length=250) #brief picture size 100 * 100
    stdPic = models.CharField(max_length=250)
    created = models.DateTimeField(auto_now_add=True) #    not display
    
    def __unicode__(self):
        return self.title



class BlogPost(models.Model):
    title = models.CharField(max_length=60)
    category = models.ForeignKey(BlogCategory)
    body = models.TextField()
    created = models.DateTimeField(auto_now_add=True)
    

    def __unicode__(self):
        return self.title

class ArtPostAdmin(admin.ModelAdmin):
    search_fields = ["title"]
    class Media:
        js = [
              '/media/scripts/tiny_mce/tiny_mce.js',
              '/media/scripts/textareas.js',
        ]

class GameDesignPostAdmin(admin.ModelAdmin):
    search_fields = ["title"]
    class Media:
        js = [
              '/media/scripts/tiny_mce/tiny_mce.js',
              '/media/scripts/textareas.js',
        ]

class ProjectPostAdmin(admin.ModelAdmin):
    search_fields = ["title"]
    class Media:
        js = [
              '/media/scripts/tiny_mce/tiny_mce.js',
              '/media/scripts/textareas.js',
        ]

class BlogPostAdmin(admin.ModelAdmin):
    search_fields = ["title"]
    class Media:
        js = [
              '/media/scripts/tiny_mce/tiny_mce.js',
              '/media/scripts/textareas.js',
        ]




class BlogComment(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    author = models.CharField(max_length=60)
    body = models.TextField()
    post = models.ForeignKey(BlogPost)

    def __unicode__(self):
        return unicode("%s: %s" % (self.post, self.body[:60]))

    def save(self, *args, **kwargs):
        """Email when a comment is added."""
        if "notify" in kwargs and kwargs["notify"] == True:
            message = "Comment was was added to '%s' by '%s': \n\n%s" % (self.post, self.author,
                                                                         self.body)
            from_addr = "no-reply@mydomain.com"
            recipient_list = ["myemail@mydomain.com"]
            #send_mail("New comment added", message, from_addr, recipient_list)

        if "notify" in kwargs: del kwargs["notify"]
        super(BlogComment, self).save(*args, **kwargs)


class BlogCommentAdmin(admin.ModelAdmin):
    display_fields = ["post", "author", "created"]

class BlogCategoryAdmin(admin.ModelAdmin):
    display_fields = ["name"]

